<template>
    <div>
      <aplid-base-crud ref="crud" class="w-100" v-bind="baseConfig">
        <template #menuColumn="{row}">
            <el-button v-if="row.reservationState==0"  text type="primary" @click="editData('bookCancel',row)">拒绝</el-button>
            <el-button v-if="row.reservationState==0"  text type="primary" @click="editData('bookPass',row)">通过</el-button>
            <!-- <el-button v-if="row.reservationState==0&&row.isChecked==1&&row.empowerState==1&&row.hasDocument==0" type="text" @click="editData('bookPass',row)">通过并且提示申请档案</el-button>
            <el-button v-if="row.reservationState==0&&row.isChecked==1&&row.empowerState==3&&row.hasDocument==1" type="text" @click="editData('bookPassAndAuth',row)">通过并且申请授权</el-button>
            <el-button v-if="row.reservationState==1&&row.isChecked==1&&row.empowerState==1&&row.hasDocument==0" type="text">提示申请档案</el-button> -->
            <el-button v-if="row.reservationState==1&&row.empowerState!=2&&row.hasDocument==1&&row.isChecked==1"  text type="primary" @click="applyAuth(row)">申请授权</el-button>
        </template>
        <template #DetailDialog="{row}">
            <Detail :rowData="row"></Detail>
        </template>
    </aplid-base-crud>
    </div>
  </template>
  
  <script setup lang="ts">
  import { ref,nextTick } from 'vue'
  import {baseConfig} from './config'
  import Detail from './components/detail/index.vue'
  import apiMod from '@/apiMod/index'
  import { ElMessage } from 'element-plus'

  const crud = ref(null)
  const handleRefreshPage = () => {
  nextTick(() => {
    crud.value.refreshChange({}, false)
  })
}
// 修改授权
 const applyAuth = (row) =>{
    let params = {
        id:row.id,
        idCard:row.idCard,
        empowerState:3,
        empowerStateLabel:'未获得授权'
    }
    apiMod.view_bscServiceOrgReservation_empower(params).then(res=>{
        if(res.code==0){
            handleRefreshPage()
            ElMessage({
                    message: '操作成功',
                    type: 'success',
            })
        }
    })
 }
  const editData = (type,row) =>{
    console.log('2222')
    let params = {}
    if(type=='bookCancel'){
        params = {
            id:row.id,
			reservationState:2,
			reservationStateLabel:'拒绝'
        }
    }else if (type=='bookPass'){
        params = {
            id:row.id,
			reservationState:1,
			reservationStateLabel:'同意'
        }
    }else if(type=='bookPassAndAuth'){
        params ={
            id:row.id,
            reservationState:1,
			reservationStateLabel:'同意'
        }
    }
    apiMod.view_bscServiceOrgReservation_pass(params).then(res=>{
            if(res.code==0){
                if(type=='bookPassAndAuth'){
                    applyAuth(row)
                }else{
                    handleRefreshPage()
                    ElMessage({
                        message: '操作成功',
                        type: 'success',
                    })
                }
               
            }
        })
  } 

  
  </script>
  <style scoped lang="scss">
  </style>